﻿using SqlSugar;
using Newtonsoft.Json;

namespace Lightworks.System.Dto
{
    public class PageData<T>
    {
        public int Total { get; set; }
        public int Page { get; set; }
        public int PageSize { get; set; }
        public Dictionary<string, object>? Summary { get; set; }
        public List<T>? Rows { get; set; }
    }

    public class SearchReq 
    {
        public int Page { get; set; }
        public int PageSize { get; set; }
        public string? Keywords { get; set; }
        [JsonProperty("prop")]
        public string? Prop { get; set; }
        [JsonProperty("order")]
        public string? Order { get; set; }

        public List<OrderByModel> GetOrderModel() 
        {
            return new List<OrderByModel> { 
                new OrderByModel
                {
                    OrderByType = this.Order == "descending" ? OrderByType.Desc : OrderByType.Asc,
                    FieldName = this.Prop == null ? "Id" : this.Prop,
                }
                
            };
        }

        public PageModel GetPageModel()
        {
            return new PageModel()
            {
                PageSize = this.PageSize,
                PageIndex = this.Page
            };
        }
    }
}
